#include "bq.hpp"
#include <stdlib.h>
#include <unistd.h>
typedef int val_type;

void* cthread_test(void* bq_)
{
    Blockqueue<val_type>* bq = static_cast<Blockqueue<val_type>*>(bq_);
    while(true)
    {
        val_type val = rand() % 20;
        bq->bqpush(val);
        std::cout << "生产者 ->" << val << std::endl;
        sleep(1);
    }
    return nullptr;
}

void* pthread_test(void* bq_)
{
    Blockqueue<val_type>* bq = static_cast<Blockqueue<val_type>*>(bq_);
    while(true)
    {
        val_type val = bq->bqpop();
        std::cout << "消费者 ->" << val << std::endl;
    }
    return nullptr;
}

int main()
{
    Blockqueue<val_type> bq;
    //创建两个线程
    pthread_t c, p;
    pthread_create(&c, nullptr, cthread_test, &bq);
    pthread_create(&p, nullptr, pthread_test, &bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    
    return 0;
}